#pragma once

#include <pthread.h>
#include <iostream>
#include"Mutex.hpp"
using namespace LockMutex;

namespace condmod
{
    class Cond
    {
    public:
    Cond()
    {
        //初始化
        int n = pthread_cond_init(&_cond,nullptr);
        (void)n;
    }
    ~Cond()
    {
        int n = pthread_cond_destroy(&_cond);
    }
    //等待
    void Wait(Mutex& mutex)
    {
        int n = pthread_cond_wait(&_cond,mutex.LockPtr());
    }
    //通知一个线程-也就是唤醒1个线程
    void Notify() 
    {
        int n = pthread_cond_signal(&_cond);
    }
    //通知全部线程-唤醒全部线程
    void NotifyAII()
    {
        int n = pthread_cond_broadcast(&_cond);
    }
    private:
        pthread_cond_t _cond;
    };
}